package day03;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/7 10:03
 * 力扣 141
 */
public class LinkedListPractice02 {

    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }
        ListNode slow = head;
        ListNode fast = head;
        while(fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast) {
                return true;
            }
        }
        return false;
    }
}
